package com.web.model;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

/**
 * @author 龚俊杰
 * 2018年6月21日
 * 会员Model
 */
public class Member extends Model<Member> {
    private static final long serialVersionUID = 2387542071731521827L;
    public static final Member me = new Member();

    public boolean saveMember(String memberId, String nickName, int age) {
        Member member = new Member();
        member.set("memberId", memberId);
        member.set("nickName", nickName);
        member.set("age", age);
        return member.save();
    }

    /**
     * 根据Id查询会员
     *
     * @param memberId
     * @return
     */
    public Member getMemberById(String memberId) {
        return me.findFirst("select * from members where memberId=? member by time_end desc", memberId);
    }

    /**
     * 根据昵称模糊查询会员信息
     *
     * @param nickName
     * @return
     */
    public List<Member> getMemberByNickName(String nickName) {
        return me.find("select * from members where nickName like ?", "%" + nickName + "%");
    }

    public Page<Member> paginate(int pageNumber, int pageSize) {
        return me.paginate(pageNumber, pageSize, "select *", "from member order by id asc");
    }
}
